package net.aetherial.context.grounding.analyzers;

import java.util.*;

import net.aetherial.context.grounding.annotators.*;
import net.aetherial.context.grounding.estimators.*;

/**
 * An analyzer that preprocesses content using annotators.
 */

public class AnnotatingAnalyzer extends Analyzer
{
	private List<Annotator> annotators;

	/**
	 * Add an annotator to the analyzer.
	 * 
	 * @param a		New annotator.
	 */
	
	public void addAnnotator (Annotator a)
	{
		if (annotators == null)
			annotators = new ArrayList<Annotator> ();
		
		annotators.add (a);
	}
	
	/**
	 * Processes a conversational unit using annotators and applies an estimator and/or classifier to generate a prediction.
	 *  
	 * @see net.aetherial.context.grounding.analyzers.Analyzer#process(java.lang.String, java.lang.String, double)
	 */

	public void process (String sender, String contribution, double score) 
	{
		Map<String, Map<String, Object>> contributionLayers = new HashMap<String, Map<String, Object>> ();

		for (Annotator a: annotators)
		{
			Map<String, Object> annotation = a.annotate (sender, contribution, score);
			
			if (annotation != null)
				contributionLayers.put (a.getLayerName (), annotation);
		}

		HashMap<String, Object> defaultLayer = new HashMap<String, Object> ();
		defaultLayer.put (Estimator.CONTRIBUTION_KEY, contribution);
		defaultLayer.put (Estimator.SENDER_KEY, sender);
		defaultLayer.put (Estimator.SCORE_KEY, score);
		
		// System.out.println ("[" + Annotator.DEFAULT_LAYER + "]: " + contribution);
		contributionLayers.put (Annotator.DEFAULT_LAYER, defaultLayer);
		
		try
		{
			// if (classifier != null)
			// 	logger.logClassification (classifier.classify (contributionLayers));
			
			if (estimator != null)
				logger.logEstimate (estimator.estimate (contributionLayers));
		}
		catch (Exception e)
		{
			e.printStackTrace ();
		}
	}
}
